package com.gthncz;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gthncz.beans.Student;

public class JDBCDemo {

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("Beans_jdbc.xml");
		StudentDAOImpl studentDAOImpl = (StudentDAOImpl) context.getBean("studentDAOImpl");
		studentDAOImpl.insert("Alice", 18);
		studentDAOImpl.insert("Bob", 20);
		studentDAOImpl.insert("carol", 20);
		studentDAOImpl.insert("Dave", 21);
		studentDAOImpl.insert("frank", 22);
		
		Student student = studentDAOImpl.getStudent(15);
		if(student != null) System.out.println(student.toString());
		
		List<Student> students = studentDAOImpl.listStudents();
		if(students != null) {
			System.out.println("--------------ALL STUDENTS-------------------");
			for (Student item:students) {
				System.out.println(item.toString());
			}
			System.out.println("--------------ALL END-----------------------");
		}

		studentDAOImpl.delete(2);
		
		students = studentDAOImpl.listStudents();
		if(students != null) {
			System.out.println("--------------ALL STUDENTS-------------------");
			for (Student item:students) {
				System.out.println(item.toString());
			}
			System.out.println("--------------ALL END-----------------------");
		}

		studentDAOImpl.deleteAll();
	}

}
